/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Eventos;

import java.util.ArrayList;

/**
 *
 * @author Overpower
 */
public class CustomEventDispatcher 
{
    protected ArrayList<CustomEventListener> _listenerList = new ArrayList<>();
    
    public void AddCustomListener( CustomEventListener _l )
    {
        _listenerList.add(_l);
    }
    
    public void RemoveCustomListener( CustomEventListener _l )
    {
        _listenerList.remove(_l);
    }
    
    public void DispatchCustomEvent( CustomEvent evt )
    {
        ArrayList<CustomEventListener> tempSpeedListenerList;

        synchronized (this) 
        {
            if (_listenerList.isEmpty())
                return;
            tempSpeedListenerList = (ArrayList<CustomEventListener>) _listenerList.clone();
        }

        for (CustomEventListener listener : tempSpeedListenerList) {
            listener.HandleCustomEvent(evt);
        }
    }
}
